
function reSetTime()
{
	$(".yj-message-blog-time").each(function (index, domEle){
    	var origTime = $(domEle).attr("title");
        origTime= new Date(Date.parse(origTime.replace(/-/g, "/"))); 
        origTime = origTime.getTime();
    	var nowTime = new Date();
    	nowTime =  nowTime.getTime();                            //获取当前时间(从1970.1.1开始的毫秒数) 
    	var gapCount = nowTime - origTime;
    	gapCount = Math.floor(gapCount /1000);                  //时间的差值，单位为s 
    	if(gapCount <=10)  $(domEle).text("10s之前");
    	if(gapCount<=60 && gapCount>10)  $(domEle).text("1分钟之前");
    	if(gapCount<60*60 && gapCount>60)  $(domEle).text(Math.floor(gapCount/60+1)+"分钟之前");
    	if(gapCount<60*60*24 && gapCount>=60*60)  $(domEle).text(Math.floor(gapCount/3600+1)+"小时之前");
    	if(gapCount>=60*60*24)  $(domEle).text(Math.floor(gapCount/(60*60*24)+1)+"天之前");
    });
}
//保存评论
function saveArticleComment(ctx){
	var content = $("#moduleComment_description").val();
	if (content.length<1){
		 jAlert('It could not be null,Please try again!', 'Alert Dialog');  $("#moduleComment_description").focus();  return;
	}
	$.ajax({
		url: ctx+"/blog/blog.action",
		type:"post",
		dataType:"json",
		data:{
			"articleComment.content":content,
			"articleId":articleId,
			"method:saveArticleComment2":"ok"
		},
		success: function(data){
			var html = "";
			var commentId = data.articleCommentId;
			var creationDate = data.creationDate;
			var description_g = data.articleCommentContent;
			$("#comment").css("display","block");
			length=length*1+1;
			html = "<div id='newcomments"+commentId+"' style='border-top: 1px dashed gray;width: 720px;'><div class='comment_title'>"+length+"楼&nbsp;&nbsp;"
			+"<a href='"+contextPath+"/blog/blog.action?method:personalArticles&blogerId="+userId+"' target='_blank'>"+me+"</a>"
			+"&nbsp;&nbsp;&nbsp;&nbsp;<a class='yj-message-blog-time' href='javascript://' title='"+creationDate+
			"'>"+creationDate+"</a> &nbsp;&nbsp;&nbsp;&nbsp;"
			+"<a href='javascript://' id='confirm"+commentId+"' class='deleteModuleComment"+commentId+"'>" 
					+"删除"+"</a></div><div class='comment_content'>";
			html = html +description_g+"</div>";
			$("#reply").prepend(html);
			$("#confirm"+commentId).live('click',function(){readyBlog();});//deleteModuleComment(commentId,ctx);
		},
		error: function(){ },
		complete : function(){ 
			$("#moduleComment_description").val('');
		}
	});
}

function rsaveArticleComment(ctx,articleCommentId){
	var content = $("#moduleComment_description_"+articleCommentId).val();
	if (content.length<1){
		 jAlert('It could not be null,Please try again!', 'Alert Dialog');  $("#moduleComment_description").focus();  return;
	}
	$.ajax({
		url: ctx+"/blog/blog.action",
		type:"post",
		dataType:"json",
		data:{
			"articleComment.content":content,
			"articleComment.parentCommentId":articleCommentId,
			"articleId":articleId,
			"method:saveArticleComment2":"ok"
		},
		success: function(data){
			var html = "";
			var parentCommentId = data.parentCommentId;
			var creationDate = data.creationDate;
			var description_g = data.articleCommentContent;
			$("#comment").css("display","block");
			html = "<div id='rnewcomments"+parentCommentId+"' style=' margin-bottom: -4px; margin-left: 30px'><div class='comment_title' style='background-color: #EAFFF9;' >&nbsp;"
			+"<a href='"+contextPath+"/blog/blog.action?method:personalArticles&blogerId="+userId+"' target='_blank'>"+me+"</a>"
			+"&nbsp;&nbsp;&nbsp;&nbsp;<a class='yj-message-blog-time' href='javascript://' title='"+creationDate+
			"'>"+creationDate+"</a> &nbsp;&nbsp;&nbsp;&nbsp;"
			+"<a href='javascript://' id='confirm"+parentCommentId+"' class='deleteReModuleComment"+parentCommentId+"'>" 
					+"删除"+"</a></div><div class='comment_content'>";
			html = html +description_g+"</div>";
			$("#rreply"+articleCommentId).append(html);
			$("#confirm"+parentCommentId).live('click',function(){readyBlog();});
		},
		error: function(){ },
		complete : function(){ 
			$("#rnewComment"+articleCommentId).hide();
		}
	});
}


function hideNotice()
{
	$("[id='yj-inline-icon x-grey-icon yj-closeFlash']").fadeOut(3000);
}
function showNotice(str)
{   $("[id='yj-inline-icon x-grey-icon yj-closeFlash']").find("p").text(str);
    $("[id='yj-inline-icon x-grey-icon yj-closeFlash']").show();
	hideNotice();
}

function readyBlog(){
	
	//博文阅读界面删除博文功能
	$("a[class^='ggdeleteModule']").live('click',function(){
	    var articleId =  $(this).attr("class").substring("ggdeleteModule".length);
		 $("#dialog-confirm").dialog({
			resizable: false,
	        height:140,
	        modal: true,
	      buttons: {
	          "YES": function() {
	        	  $.ajax(
	      	 			{
	      	 				url: contextPath+"/blog/blog.action",
	      	 				type:"post",
	      	 				dataType:"json",
	      	 				data:{
	      	 					articleId:articleId,
	      	 					userId:userId,
	      	 					"method:ajaxDeleteArticle":"xx"
	      	 				},
	      	 				 success:function(data) {
	      	 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
	      	 					 else{
	      	 						 window.location.href=contextPath+"/blog/blog.action?method:articleIndex";
	      	 						 showNotice("博文删除成功");
	      	 					 }
	      	 				 }
	      	 				}
	      	 	);
	            	 
	            	 $( this ).dialog( "close" );
	            	 return false;
	          },
	          "NO": function() {
	              $( this ).dialog( "close" );
	              return false;
	          }                           
	      }
	  }); 
	});

	 
	//删除博客评论
	 $("a[class^='deleteModuleComment']").live('click',function(){
	     var articlecommentId =  $(this).attr("class").substring("deleteModuleComment".length);
		 var parent = $("[id=newcomments"+articlecommentId+"]");
		 $("#dialog-confirm").dialog({
			 resizable: false,
             height:140,
             modal: true,
           buttons: {
               "YES": function() {
            	   $.ajax(
           	 			{
           	 				url: contextPath+"/blog/blog.action",
           	 				type:"post",
           	 				dataType:"json",
           	 				data:{
           	 				articlecommentId:articlecommentId,
           	 					userId:userId,
           	 					"method:ajaxDeleteArticleComment":"xx"
           	 				},
           	 				 success:function(data) {
           	 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
           	 					 else{
           	 					 parent.remove();
           	 	               	 showNotice("评论删除成功");
           	 					 }
           	 				 }
           	 			}
           	 	);
	 	        $( this ).dialog( "close" );
               	 return false;
               },
               "NO": function() {
                   $( this ).dialog( "close" );
                   return false;
               }                           
           }
       }); 
	 });
	 
	//删除博客评论的回复
	 $("a[class^='deleteReModuleComment']").live('click',function(){
	     var rarticlecommentId =  $(this).attr("class").substring("deleteReModuleComment".length);
		 var parent = $("[id=rnewcomments"+rarticlecommentId+"]");
		 $("#dialog-confirm").dialog({
			 resizable: false,
             height:140,
             modal: true,
           buttons: {
               "YES": function() {
            	   $.ajax(
              	 			{
              	 				url: contextPath+"/blog/blog.action",
              	 				type:"post",
              	 				dataType:"json",
              	 				data:{
              	 					rarticlecommentId:rarticlecommentId,
              	 					userId:userId,
              	 					"method:ajaxDeleteReArticleComment":"xx"
              	 				},
              	 				 success:function(data) {
              	 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
              	 					 else{            	 			    	   
              	 	                 	 parent.remove();
              	 	                 	 showNotice("评论删除成功");
              	 					 }
              	 				 }
              	 			}
              	 	);
                 	 $( this ).dialog( "close" );
                 	 return false;
               },
               "NO": function() {
                   $( this ).dialog( "close" );
                   return false;
               }                           
           }
       }); 
	 });
	 
	 //删除博文
	 $("a[class^='gdeleteModule']").live('click',function(){
	     var articleId =  $(this).attr("class").substring("gdeleteModule".length);
		 var parent = $("[id=newModule"+articleId+"]");
		 $("#dialog-confirm").dialog({
			 resizable: false,
             height:140,
             modal: true,
           buttons: {
               "YES": function() {
            	   $.ajax(
   	      	 			{
   	      	 				url: contextPath+"/blog/blog.action",
   	      	 				type:"post",
   	      	 				dataType:"json",
   	      	 				data:{
   	      	 				articleId:articleId,
   	      	 					userId:userId,
   	      	 					"method:ajaxDeleteArticle":"xx"
   	      	 				},
   	      	 				 success:function(data) {
   	      	 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
   	      	 					 else{
   	      	                 	 parent.remove();
   	      	                 	 showNotice("博文删除成功");
   	      	 					 }
   	      	 				 }
   	      	 				}
   	      	 	);
                 	 $( this ).dialog( "close" );
                 	 return false;
               },
               "NO": function() {
                   $( this ).dialog( "close" );
                   return false;
               }                           
           }
       }); 
	 });
	 //删除博客！
	 $("a[class^='deleteProject']").live('click',function(){
	     var blogId =  $(this).attr("class").substring("deleteProject".length);
		 var parent = $("[id=newprojects"+blogId+"]");
		 $("#dialog-confirm").dialog({
			 resizable: false,
             height:140,
             modal: true,
           buttons: {
               "YES": function() {
            	   $.ajax(
      	      	 			{
      	      	 				url: contextPath+"/blog/blog.action",
      	      	 				type:"post",
      	      	 				dataType:"json",
      	      	 				data:{
      	      	 				blogId:blogId,
      	      	 					userId:userId,
      	      	 					"method:ajaxDeleteBlog":"xx"
      	      	 				},
      	      	 				 success:function(data) {
      	      	 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
      	      	 					 else{
      	      	                 	 parent.remove();
      	      	                 	 showNotice("项目删除成功");
      	      	 					 }
      	      	 				 }
      	      	 				}
      	      	 	);
                 	 $( this ).dialog( "close" );
                 	 return false;
               },
               "NO": function() {
                   $( this ).dialog( "close" );
                   return false;
               }                           
           }
       }); 
	 });
	 
	
	 //博客收藏的操作
	  	$("[id^='markImg_']").live('click',function(){
				var mark = $(this);
				var articleId = $(this).attr("id").substring("markImg_".length);
				if(mark.attr("src").indexOf("on")>0){
					mark.attr("src",mark.attr("src").replace("on","off"));
					$.ajax(
				 			{
				 				url: contextPath+"/blog/ajaxrpc.action",
				 				type:"post",
				 				dataType:"json",
				 				data:{
				 					articleId:articleId,
				 					userId:userId,
				 					"method:ajaxDeleteBlogCollect":"xx"
				 				},
				 				 success:function(data) {
				 					 if(data.result == 'No Permission')  alert("抱歉你没有删除权限");
				 				 }
				 				}
				 	);
					showNotice("删除博客收藏");
				}else{
					mark.attr("src",mark.attr("src").replace("off","on"));
					 $.ajax(
					 			{
					 				url: contextPath+"/blog/ajaxrpc.action",
					 				type:"post",
					 				dataType:"json",
					 				data:{
					 					articleId:articleId,
					 					userId:userId,
					 					"method:ajaxInsertBlogCollect":"xx"
					 				},
					 				 success:function(data) {
					 					 if(data.result == 'Fail')  alert("Fail to insert a data!");
					 				 }
					            }
					 	);
					showNotice("收藏博客成功");
				}
	  		});
 	 
	 

}
